package c.j.a.d.b.o;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.SystemClock;
import android.text.TextUtils;
import c.j.a.d.b.b.e;
import c.j.a.d.b.e.b;
import c.j.a.d.b.e.d;
import c.j.a.d.b.e.i;
import c.j.a.d.b.e.p;
import c.j.a.d.b.j.q;
import com.ss.android.socialbase.downloader.g.c;
import com.ss.android.socialbase.downloader.notification.DownloadNotificationService;
import java.util.ArrayList;
import java.util.Objects;

/* compiled from: DownloadNotificationService */
public class a implements Runnable {
    public final /* synthetic */ Intent a;
    public final /* synthetic */ String b;
    public final /* synthetic */ DownloadNotificationService c;

    /* compiled from: DownloadNotificationService */
    public class a implements Runnable {
        public final /* synthetic */ NotificationManager a;
        public final /* synthetic */ int b;
        public final /* synthetic */ Notification c;

        public a(NotificationManager notificationManager, int i, Notification notification) {
            this.a = notificationManager;
            this.b = i;
            this.c = notification;
        }

        public void run() {
            DownloadNotificationService downloadNotificationService = a.this.c;
            NotificationManager notificationManager = this.a;
            int i = this.b;
            Notification notification = this.c;
            String str = DownloadNotificationService.c;
            downloadNotificationService.b(notificationManager, i, notification);
        }
    }

    public a(DownloadNotificationService downloadNotificationService, Intent intent, String str) {
        this.c = downloadNotificationService;
        this.a = intent;
        this.b = str;
    }

    public void run() {
        NotificationManager notificationManager = (NotificationManager) this.c.getSystemService("notification");
        boolean z = false;
        int intExtra = this.a.getIntExtra("DOWNLOAD_NOTIFICATION_BUNDLE_EXTRA_ID", 0);
        if (this.b.equals("android.ss.intent.action.DOWNLOAD_NOTIFICATION_NOTIFY")) {
            Notification notification = (Notification) this.a.getParcelableExtra("DOWNLOAD_NOTIFICATION_BUNDLE_EXTRA");
            int intExtra2 = this.a.getIntExtra("DOWNLOAD_NOTIFICATION_EXTRA_STATUS", 0);
            if (!(intExtra == 0 || notification == null || notificationManager == null)) {
                if (intExtra2 == 4) {
                    i a = i.a(b.a());
                    Objects.requireNonNull(a);
                    if (c.j.a.c.y.a.i.s(4194304)) {
                        synchronized (a) {
                            p h = d.b().h(intExtra);
                            if (h != null) {
                                z = h.e(intExtra);
                            }
                        }
                    } else {
                        p h2 = d.b().h(intExtra);
                        if (h2 != null) {
                            z = h2.e(intExtra);
                        }
                    }
                    if (z) {
                        c k = i.a(b.a()).k(intExtra);
                        if (DownloadNotificationService.j) {
                            if (k != null && k.w() && System.currentTimeMillis() - DownloadNotificationService.i > DownloadNotificationService.k) {
                                this.c.b(notificationManager, intExtra, notification);
                                k.p0.set(SystemClock.uptimeMillis());
                            }
                        } else if (k != null && k.w()) {
                            this.c.b(notificationManager, intExtra, notification);
                            k.p0.set(SystemClock.uptimeMillis());
                        }
                    }
                } else if (intExtra2 == -2 || intExtra2 == -3) {
                    if (DownloadNotificationService.j) {
                        DownloadNotificationService.c(this.c, notificationManager, intExtra, notification);
                    } else {
                        Handler handler = this.c.b;
                        if (handler != null) {
                            handler.postDelayed(new a(notificationManager, intExtra, notification), intExtra2 == -2 ? 50 : 200);
                        }
                    }
                } else if (DownloadNotificationService.j) {
                    DownloadNotificationService.c(this.c, notificationManager, intExtra, notification);
                } else {
                    this.c.b(notificationManager, intExtra, notification);
                }
            }
        } else if (this.b.equals("android.ss.intent.action.DOWNLOAD_NOTIFICATION_CANCEL")) {
            if (intExtra != 0) {
                DownloadNotificationService downloadNotificationService = this.c;
                String str = DownloadNotificationService.c;
                downloadNotificationService.a(notificationManager, intExtra);
            }
        } else if (this.b.equals("android.net.conn.CONNECTIVITY_CHANGE")) {
            try {
                if (c.j.a.d.b.n.a.u(this.c, "android.permission.ACCESS_NETWORK_STATE")) {
                    ConnectivityManager connectivityManager = (ConnectivityManager) this.c.getSystemService("connectivity");
                    if (connectivityManager != null) {
                        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                        if (activeNetworkInfo != null) {
                            if (activeNetworkInfo.isConnected()) {
                                ArrayList arrayList = new ArrayList();
                                if (!TextUtils.isEmpty(e.a)) {
                                    arrayList.add(e.a);
                                }
                                arrayList.add("mime_type_plugin");
                                Context applicationContext = this.c.getApplicationContext();
                                if (applicationContext != null) {
                                    i.a(applicationContext).f(arrayList);
                                    Objects.requireNonNull(i.a(applicationContext));
                                    Objects.requireNonNull(d.b());
                                    p a2 = q.a(false);
                                    if (a2 != null) {
                                        a2.U(arrayList);
                                    }
                                    p a3 = q.a(true);
                                    if (a3 != null) {
                                        a3.U(arrayList);
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (this.b.equals("android.intent.action.MEDIA_UNMOUNTED") || this.b.equals("android.intent.action.MEDIA_REMOVED") || this.b.equals("android.intent.action.MEDIA_BAD_REMOVAL") || this.b.equals("android.intent.action.MEDIA_EJECT")) {
            try {
                Objects.requireNonNull(i.a(this.c));
                Objects.requireNonNull(d.b());
                p a4 = q.a(false);
                if (a4 != null) {
                    a4.a();
                }
                a4 = q.a(true);
                if (a4 != null) {
                    a4.a();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
